import {Component, OnInit} from '@angular/core';
import {adSystemApiUrl} from '../../../../config/api';
import {HttpService} from '../../../lib/service/http.service';

export class AddAccount {
  name: string;
  mobile: number;
  email: string;
  password: string;
  password_again: string;
}

@Component({
  selector: 'app-member-add',
  templateUrl: 'member-add.component.html',
  styleUrls: ['member-add.component.scss'],
})
export class MemberAddComponent implements OnInit {

  addAccount = new AddAccount;

  type: string;
  message: string;
  isShow = false;

  constructor(private httpService: HttpService) {
  }

  ngOnInit() {
  }

  addUser() {
    const url = `${adSystemApiUrl}/v1/admin/account/add`;
    return this.httpService.httpPostAuth(url, this.addAccount).subscribe(
      res => {
        if (res.code === 2000) {
          this.type = 'success';
          this.message = '添加成功';
          this.isShow = true;
        } else {
          this.type = 'error';
          this.message = res.message;
          this.isShow = true;
        }
      }
    );
  }
}
